import requests
import hashlib
import time

from utils.common_util import CommonUtil


# 生成签名
def get_sign():
    se = '30hwe3fc78239fghtik59'
    data = {
        "pageSize": 10,
        "createEndLong": "1730861027000",
        "pageNum": 1,
        "createStartLong": "1730429027000",
    }

    secret = se
    stringA = '&'.join(["{0}={1}".format(k, data.get(k)) for k in sorted(data)])
    # timestamp = str(CommonUtil.get_timestamp())
    timestamp = '1732589091985'
    stringA = "{}{}{}".format(secret, stringA, timestamp)
    md5 = hashlib.md5()
    md5.update(stringA.encode("utf8"))
    a, b = md5.hexdigest(), timestamp
    return a, b

# 生成签名
sign,timestamp = get_sign()

# 接口URL
url = "https://mp.idimage.com.cn/standard-bossapi/apply/open/mouth/list"

# 请求参数
data = {
    "sign": sign,
    "pageSize": 10,
    "createEndLong": "1730861027000",
    "pageNum": 1,
    "createStartLong": "1730429027000",
    "timestamp": timestamp
}

# 请求头
headers = {
    "Content-Type": "application/json",
}

# 发送POST请求
response = requests.post(url, json=data, headers=headers)

# 检查响应状态码
if response.status_code == 200:
    # 解析响应内容
    data = response.json()
    print("请求成功")
    print("响应数据:", data)
else:
    print(f"请求失败，状态码: {response.status_code}")
    print("响应内容:", response.text)
